package com.etone.smartFlow.service.impl;

import com.etone.smartAudit.commService.CommPUumUserinfoService;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.dto.PageDTO;
import com.etone.smartAudit.vo.PUumOrgVO;
import com.etone.smartAudit.vo.PUumUserinfoVO;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartFlow.domain.dto.FlowUserDTO;
import com.etone.smartFlow.domain.vo.FlowRoleVo;
import com.etone.smartFlow.domain.vo.FlowUserVo;
import com.etone.smartFlow.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysUserServiceImpl implements ISysUserService {

    @Autowired
    private CommPUumUserinfoService  pUumUserinfoService;
    @Override
    public List<FlowUserVo> selectUserList(FlowUserDTO dto) {
        PageDTO pageDTO = new PageDTO();
        pageDTO.setKey(dto.getKey());
        pageDTO.setOuguId(dto.getOuguId());
        pageDTO.setPage(1);
        pageDTO.setPageSize(1000);
        PagerVO<PUumUserinfoVO> list = pUumUserinfoService.getUsersPage(pageDTO);
        List<FlowUserVo> voList = new ArrayList<>();
        list.getRows().stream().forEach(user -> {
            FlowRoleVo roleVo = new FlowRoleVo();
            roleVo.setName(user.getDepartment());
            FlowUserVo vo = FlowUserVo.builder()
                    .role(roleVo)
                    .nickName(user.getFullName())
                    .userId(user.getUserID())
                    .build();

            voList.add(vo);
        });
        return voList;
    }

    @Override
    public FlowUserVo selectUserById(String userId) {
        PUumUserinfoVO userinfoVO = pUumUserinfoService.getUserInfoByUserId(userId);
        FlowRoleVo roleVo = new FlowRoleVo();
        roleVo.setName(userinfoVO.getDepartment());
        FlowUserVo vo = FlowUserVo.builder()
                .role(roleVo)
                .nickName(userinfoVO.getFullName())
                .userId(userinfoVO.getUserID())
                .build();
        return vo;
    }
}
